//
//  WKPresentationController.swift
//  WeiBo
//
//  Created by wukeng on 16/8/23.
//  Copyright © 2016年 wukeng. All rights reserved.
//

import UIKit
class WKPresentationController: UIPresentationController {
    var presentedFrame : CGRect = CGRectZero
    //MARK:- 懒加载属性
    private lazy var coverView : UIView = UIView()
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        //设置弹出尺寸
        presentedView()?.frame = presentedFrame
        
        //添加蒙版
        setupCoverView()
    }
}

//MARK:- 设置UI界面相关
extension WKPresentationController{
    private func setupCoverView(){
        containerView?.insertSubview(coverView, atIndex: 0)
        //设置蒙版
        coverView.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        coverView.frame = containerView!.bounds
        //监听点击事件
        let tap = UITapGestureRecognizer(target: self, action: #selector(WKPresentationController.coverViewClick))
        coverView.addGestureRecognizer(tap)
        
    }
}

//MARK:- 点击事件
extension WKPresentationController{
   @objc private func coverViewClick() {
    presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }
}